home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Funschool 2 disk 3.adf / part5.c < prev    next >
C/C++ Source or Header  |  1987-06-17  |  5KB  |  185 lines

  1.  
  2.  
  3.  
  4. /*Your Amiga*/
  5. /*amiga.lib rules ok!*/
  6. /*part5-scrolling*/
  7. /*c source code*/
  8.  
  9. #include <exec/types.h>
  10. #include  <graphics/gfx.h>
  11. #include  <graphics/view.h>
  12. #include  <graphics/rastport.h>
  13. #include  <graphics/gfxbase.h>
  14. #include  <intuition/intuition.h>
  15.  
  16. long dosbase=0;                        /*library pointer*/
  17. long libraries=0;
  18. long i,k;                              /*loop variables*/
  19. short j;
  20. struct GfxBase *GfxBase;               /*graphics base*/
  21. struct View myview;                    /*view*/
  22. struct View *oldview;                  /*viewports*/
  23. struct ViewPort vpredandgrey;
  24. struct ColorMap *colourmap2;
  25. struct BitMap   BMred;
  26. struct ColorMap *GetColorMap();       /*returned colormap pointer*/
  27. struct RastPort redrastport;
  28. UWORD *colourtable2;
  29.  
  30. static USHORT colours2[] =
  31. {
  32. 0x000,0xf00,0xe00,0xc00,0xa00,0x800,0x600,0x400,
  33. 0xeee,0xccc,0xaaa,0x999,0x777,0x666,0x444,0xddd,
  34. 0,0,0,0,0,0,0,0,
  35. 0,0,0,0,0,0,0,0
  36. };
  37.  
  38. struct Screen *customscreen;            /*pointer to screen structure*/
  39. struct Window *thiswindow;              /*pointers to window structures*/
  40.  
  41. struct NewScreen TheNewScreen =         /*the new screen structure*/
  42. {
  43.  0,0,320,200,3,
  44.  1,3,
  45.  NULL,
  46.  CUSTOMSCREEN,
  47.  NULL,
  48.  "custom screen",
  49.  NULL,
  50.  NULL
  51. };
  52.  
  53. struct NewWindow TheNewWindow =       /*a new window structure*/
  54. {
  55.  20,20,150,50,0,1,CLOSEWINDOW,
  56.  WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SIZEBRIGHT,
  57.  0,0,"this window",
  58.  0,0,
  59.  64,20,300,200,
  60.  CUSTOMSCREEN,
  61. };
  62.  
  63. struct RasInfo rired =
  64. {
  65. 0,&BMred,0,0
  66. };
  67. main()
  68. {
  69. libraries= openlibraries();            /*open the libraries*/
  70. if (libraries == 0) exit(1);
  71. init();                                /*initialise the viewports*/
  72. oldview  =  GfxBase->ActiView;         /*store the old view address*/
  73. remakedisplay();                       /*load the new view*/
  74. stripes();
  75. scroll();
  76. LoadView(oldview);                     /*replace the old view*/
  77. Delay(200);
  78. cleanup();
  79. closelibraries();                      /*close the libraries*/
  80. }
  81. openlibraries()
  82. {
  83. dosbase= OpenLibrary("dos.library",0);
  84. if (dosbase == 0) return(0);
  85. GfxBase= (struct GfxBase *)OpenLibrary("graphics.library",0);
  86. if (GfxBase == 0) return(0);
  87. return(1);
  88. }
  89. init()
  90. {
  91. InitView(&myview);                    /*initialise the view*/
  92. myview.ViewPort = &vpredandgrey;            /*connect it to the first viewport*/
  93. InitVPort(&vpredandgrey);             /*initialise the second viewport*/
  94. vpredandgrey.DWidth = 320;
  95. vpredandgrey.DHeight = 200;
  96. vpredandgrey.RasInfo = &rired;        /*connect it to the first RasInfo*/
  97. colourmap2 = GetColorMap(32);
  98. colourtable2 = (UWORD *)colourmap2->ColorTable;
  99. for(i=0;i<32;i++)                    /*the first 8 red colour registers are*/
  100. {                                    /*for the first playfield, the next 8*/
  101. *colourtable2++ = colours2[i];       /*grey colour registers are for the*/
  102. }                                    /*second playfield*/
  103. vpredandgrey.ColorMap = colourmap2;
  104. InitBitMap(&BMred,3,640,400);        /*a separate bitmap for each RasInfo*/
  105. for(i=0;i<3;i++)
  106. {
  107. BMred.Planes[i] = (PLANEPTR)AllocRaster(640,400);
  108. if (BMred.Planes[i] == 0) exit(2);
  109. }
  110. }
  111. scroll()
  112. {
  113. Delay(100);
  114. for(i=0;i<100;i++)   scrollx(i);
  115. Delay(100);
  116. for(i=0;i<100;i++)   scrolly(i);
  117. Delay(100);
  118. for(i=100;i>0;i--)   scrollx(i);
  119. Delay(100);
  120. for(i=100;i>0;i--)   scrolly(i);
  121. }
  122. scrollx(i)
  123. long i;
  124. {
  125. rired.RxOffset=i;
  126. remakedisplay();
  127. }
  128. scrolly(i)
  129. long i;
  130. {
  131. rired.RyOffset=i;
  132. remakedisplay();
  133. }
  134. remakedisplay()
  135. {
  136. MakeVPort(&myview,&vpredandgrey);
  137. MrgCop(&myview);                   /*merge the copper lists*/
  138. WaitTOF();                         /*wait for top of frame*/
  139. LoadView(&myview);                 /*and load the new view*/
  140. }
  141. stripes()
  142. {
  143. InitRastPort(&redrastport);
  144. redrastport.BitMap = &BMred;
  145. for(i=0;i<31;i++)
  146. {
  147. SetAPen(&redrastport,i%8);
  148. RectFill(&redrastport,20*i,0,32+20*i,400);
  149. }
  150. for(i=0;i<20;i++)
  151. {
  152. SetAPen(&redrastport,i%8);
  153. RectFill(&redrastport,0,20*i,639,10+20*i);
  154. }
  155. }
  156. cleanup()
  157. {
  158. FreeVPortCopLists(&vpredandgrey);
  159. FreeColorMap(colourmap2);
  160. for (i=0;i<3;i++)
  161. {
  162. FreeRaster(BMred.Planes[i],640,400);
  163. }
  164. }
  165. closelibraries()
  166. {
  167. CloseLibrary(dosbase);
  168. CloseLibrary(GfxBase);
  169. }
  170. window()
  171. {
  172. customscreen= (struct Screen *) OpenScreen(&TheNewScreen);
  173. if (customscreen == 0) exit(1);                   /*open the screen*/
  174.  
  175. TheNewWindow.Screen = customscreen;              /*open this window*/
  176. if ((thiswindow = (struct Window *)OpenWindow(&TheNewWindow))  == NULL) exit(FALSE);
  177.  
  178.  
  179. Wait(1<<thiswindow->UserPort->mp_SigBit);        /*wait for mousclick on*/
  180.                                                  /*thiswindow close gadget*/
  181. CloseWindow(thiswindow);                         /*close windows*/
  182. CloseScreen(customscreen);                       /*close screen*/
  183. }
  184.  
  185.